package com.gscitysfy.cus.drain.modules.command.controller;

import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.modules.command.dto.InstructTaskDto;
import com.gscitysfy.cus.drain.modules.command.service.IAppletService;
import com.gscitysfy.cus.drain.modules.command.vo.AppletQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author jiang_wen
 * @Date 2022/10/25 15:26
 * @Description TODO
 */
@Tag(name = "指挥调度 -> 小程序端API")
@AllArgsConstructor
@RestController
@RequestMapping(value = "/applet")
public class AppletController {

    private final IAppletService iAppletService;

    @Operation(summary = "获取任务列表")
    @GetMapping("/list")
    public Result<List<InstructTaskDto>> fetchList(AppletQuery query) {
        return Result.content(iAppletService.list(query));
    }

    @Operation(summary = "获取任务详情")
    @GetMapping("/{cmKid}")
    public Result<InstructTaskDto> getById(@PathVariable Long cmKid) {
        return Result.content(iAppletService.getById(cmKid));
    }

    @Operation(summary = "任务状态变更")
    @PutMapping("/changeStatus")
    public Result<String> changeStatus(@RequestBody @Validated InstructTaskDto instructTaskDto) {
        iAppletService.update(instructTaskDto);
        return Result.content("任务状态变更成功");
    }

    @Operation(summary = "已到达任务地")
    @PutMapping("/arrive/{cmKid}")
    public Result<String> arrive(@PathVariable Long cmKid) {
        iAppletService.arrive(cmKid);
        return Result.content("已到达任务地提交成功");
    }

    @Operation(summary = "是否中止任务")
    @PutMapping("/suspend/{cmKid}")
    public Result<String> suspend(@PathVariable Long cmKid) {
        iAppletService.suspend(cmKid);
        return Result.content("中止任务提交成功");
    }

    @Operation(summary = "反馈现场信息")
    @PutMapping("/feedback")
    public Result<String> feedback(@RequestBody @Validated InstructTaskDto instructTaskDto) {
        iAppletService.update(instructTaskDto);
        return Result.content("反馈现场信息成功");
    }

    @Operation(summary = "完成任务")
    @PutMapping("/complete")
    public Result<String> complete(@RequestBody @Validated InstructTaskDto instructTaskDto) {
        instructTaskDto.setCloseFlag(true);
        iAppletService.update(instructTaskDto);
        return Result.content("完成任务提交成功");
    }

}
